<?php 
include_once dirname(__FILE__)."/db.class.php" ;
 class aa_complement_infos_porteur{
		 protected $_result;
		 protected $_cnn;
		 protected $_id;
		 protected $_label;
		 protected $_choix;
		 protected $_observation;
		 protected $_CIN;
		 public function get_name_table(){ return "aa_complement_infos_porteur";}
		 public function get_name_id(){ return "id";}
		 public function get_name_label(){ return "label";}
		 public function get_name_choix(){ return "choix";}
		 public function get_name_observation(){ return "observation";}
		 public function get_name_CIN(){ return "CIN";}
		 public function set_id($parametre){  $this->_id=$parametre;}	
		 public function set_label($parametre){  $this->_label=$parametre;}	
		 public function set_choix($parametre){  $this->_choix=$parametre;}	
		 public function set_observation($parametre){  $this->_observation=$parametre;}	
		 public function set_CIN($parametre){  $this->_CIN=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id(){ return $this->_id;}
		 public function get_label(){ return $this->_label;}
		 public function get_choix(){ return $this->_choix;}
		 public function get_observation(){ return $this->_observation;}
		 public function get_CIN(){ return $this->_CIN;}
public function __construct(){

		 	 	$this->_cnn=new Db();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 aa_complement_infos_porteur(
			label,
			choix,
			observation,
			CIN)
 VALUES(
			'".$this->_label."',
			'".$this->_choix."',
			'".$this->_observation."',
			'".$this->_CIN."')";
//echo $sql
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_label)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
label='".$this->_label."'";
}
if(!empty($this->_choix)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
choix='".$this->_choix."'";
}
if(!empty($this->_observation)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
observation='".$this->_observation."'";
}
if(!empty($this->_CIN)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
CIN='".$this->_CIN."'";
}
$sql="UPDATE 
aa_complement_infos_porteur SET 
 ".$sql."
								WHERE 1=1  AND id ='".$this->_id."'";

$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function DELETE()
 {

 $sql="DELETE FROM 
aa_complement_infos_porteur 
 
									WHERE 1=1  AND id ='".$this->_id."'";
////echo $sql
$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
//$this->_cnn->disconnect();
if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return true;}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
aa_complement_infos_porteur ";

$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id,
		label,
		choix,
		observation,
		CIN
 FROM 
 aa_complement_infos_porteur";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}

$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function SELECT_S($constraint="",$pagination="")
{

$sql=" SELECT  ac.id ,ac.label ,a.observation,a.choix FROM `aa_complement_infos` ac 
LEFT JOIN aa_complement_infos_porteur a ON ac.id = a.label ".$constraint."";

//if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}

$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
 if(!$this->_result){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function countRowInTable($constraint="")
{

$sql=" SELECT 
  COUNT(*) AS total 
 FROM 
 aa_complement_infos_porteur ";
	$this->_cnn->connect();
$this->_result=$this->_cnn->query($sql);
$this->_cnn->disconnect();
$donnees_total=mysql_fetch_assoc($this->_result);
return $donnees_total['total'];
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id=$row->id;
		$this->_label=$row->label;
		$this->_choix=$row->choix;
		$this->_observation=$row->observation;
		$this->_CIN=$row->CIN;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>